﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ChineseSchool.Models.Hethong;
using ChineseSchool.Models;
using ChineseSchool.BLL;

namespace ChineseSchool
{
    public partial class ViewPage : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                lblContent.Text = LoadPageContent();
                lblFacebook.Text = loadFacebook();
            }
        }

        public string LoadPageContent()
        {
            string strPage = "";
            if (Request.QueryString["id"] != null && Request.QueryString["id"] != "")
            {
                int MenuID = int.Parse(Request.QueryString["id"]);
                M_Page M_Page = new M_Page();
                List<M_Page> lstPage = (new B_Page()).GetBy_MenuID(MenuID);
                string PageContent = "Trang web đang được xây dựng! Vui lòng trở lại sau!";
                if (lstPage.Count > 0)
                {
                    string Title = lstPage[0].title.ToString();
                    PageContent = lstPage[0].pageContent.ToString();
                    lblTitle.Text = Title;
                    Page.Title = "" + Title + "";
                    Page.MetaDescription = "" + Title + "";
                    Page.MetaKeywords = "" + Title + "";
                }
                else
                {
                    Page.Title = "Học tiếng trung hiệu quả";
                }
                strPage += "<div>" + PageContent + "</div>";
            }
            return strPage;
        }

        public string loadFacebook()
        {
            string strFacebook = "";
            if (Request.QueryString["id"] != null && Request.QueryString["id"] != "")
            {
                int MenuID = int.Parse(Request.QueryString["id"]);
                M_Menu M_Menu = (new B_Menu()).GetByPK(MenuID);
                string MenuName = M_Menu.menuName.ToString();
                string curURL = Util.MakeLinkMenuInfo(MenuID.ToString(), Encode.Uni2KD(MenuName));
                string share = "http://www.facebook.com/share.php?u=" + curURL + ";";
                if (curURL != "")
                {
                    //strFacebook += "<div class=\"fb-like\" data-href=\"" + curURL + "\" data-send=\"true\" data-width=\"660\" data-show-faces=\"true\">";
                    //strFacebook += "</div>";
                    //strFacebook += "<div>";
                    //strFacebook += "<a href=\"" + share + "\" onclick=\"return fbs_click()\" target=\"_blank\" class=\"fb_share_link\">";
                    //strFacebook += "Chia sẻ trên Facebook</a>";
                    //strFacebook += "</div>";
                    strFacebook += "<div class=\"fb-comments\" data-href=\"" + curURL + "\" data-width=\"660\" data-num-posts=\"10\">";
                    strFacebook += "</div>";
                }
            }
            return strFacebook;
        }
    }
}